package com.ilancuo.datastructuresandalgorithmsinjava.ch04_stack_list;

/**
 * Created by ilancuo on 2018/8/21.
 */
class Queue1 {
    private int maxSize;
    private long[] queryArray;
    private int front;
    private int rear;

    public Queue1(int s) {
        maxSize = s + 1;
        queryArray = new long[maxSize];
        front = 0;
        rear = -1;
    }

    public void insert(long j) {
        if (rear == maxSize - 1)
            rear = -1;
        queryArray[++rear] = j;
    }

    public long remove() {
        long temp = queryArray[front++];
        if (front == maxSize)
            front = 0;
        return temp;
    }

    public long peek() {
        return queryArray[front];
    }

    public boolean isEmpty() {
        return (rear + 1 == front || front + maxSize - 1 == rear);
    }

    public boolean isFull() {
        return (rear + 2 == front || front + maxSize - 2 == rear);
    }

    public int size() {
        if (rear >= front)
            return rear - front + 1;
        else
            return (maxSize - front) + (rear + 1);
    }
}

public class Queue_1 {
}
